const URLS={
  hotUrl:'https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items',
  latestUrl:"https://m.douban.com/rexxar/api/v2/subject_collection/movie_latest/items",
  searchUrl:"https://m.douban.com/rexxar/api/v2/search"
};



const ajaxRequest=function(options={}){
  return new Promise(function(resolve,reject){
      options.success=resolve;
      options.fail=reject;
      wx.request(options);
  });
  
};
//搜索电影
const searchFilm=function(keywords){
  return ajaxRequest({
      url:URLS.searchUrl,
      method:"GET",
      data:{
          q:keywords
      }
  });

};



//查询影院热映数据

// https://m.douban.com/rexxar/api/v2/subject_collection/movie_showing/items?start=0&count=6&for_mobile=1&ck=sew4;
const loadHotFilms=function(start=0,count=6){
    return ajaxRequest({
        url:URLS.hotUrl,
        method:"GET",
        data:{
          start:start,
          count:count,
          for_mobile:1,
          ck:"sew4"
        }
    });

};


// https://m.douban.com/rexxar/api/v2/subject_collection/movie_latest/items?start=0&count=10&for_mobile=1&ck=sew4;
const loadLatestFilms=function(start=0,count=6){
  return ajaxRequest({
      url:URLS.latestUrl,
      method:"GET",
      data:{
        start:start,
        count:count,
        for_mobile:1,
        ck:"sew4"
      }
  });

};

module.exports={
  searchFilm,
  loadHotFilms,
  loadLatestFilms
 
};